#include <GL/glut.h>

GLfloat angle = 0.0;

//blending
void cubeBlend (void) {
glRotatef(angle, 1.0, 0.0, 0.0);
glRotatef(angle, 0.0, 1.0, 0.0);
glRotatef(angle, 0.0, 0.0, 1.0);
glColor4f(1.0, 0.0, 0.0, 0.2); //set the color and alpha of the cube 2
glutSolidCube(2);
glColor4f(0.0, 1.0, 0.0, 0.5); //set the color and alpha of the cube 1
glutSolidCube(1);
}

void display (void) {
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); //enable the blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set the blend function
glLoadIdentity(); 
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
cubeBlend();
glutSwapBuffers();
angle ++;
}

void keyboard (unsigned char key, int x, int y) {
	if (key==27) { //27 is the ascii code for the ESC key
		exit (0); //end the program
	}
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
}

int main (int argc, char **argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA); //set the alpha buffer 
											//this is giving the program buffer to draw what it has to, then transfer
											//what is acctually needed to the screen.
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("A basic OpenGL Window");
glutDisplayFunc (display);
glutIdleFunc (display);
glutKeyboardFunc (keyboard);
glutReshapeFunc (reshape);
glutMainLoop ();
return 0;
}

